package com.useeinfo.oa.modules.wuHanCommon.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.CommonSugar;
import com.useeinfo.oa.modules.wuHanCommon.base.enums.MeterReadingEnum;
import com.useeinfo.oa.modules.wuHanCommon.base.enums.PointSystem;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

/**
 * 所属设备
 */
@Entity
@Table(name = "wuhan_unit")
public class WuHanUnit extends SuperClassEntity<WuHanUnit> {

    /**
     * 设备
     */
    private String unit;
    /**
     * 所属机组
     */
    @Enumerated(EnumType.STRING)
    private MeterReadingEnum meterReadingEnum;
    /**
     * 所属系统
     */
    @Enumerated(EnumType.STRING)
    private PointSystem pointSystem;

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();

        jsonObject.put("unit", CommonSugar.getTypedDefault(getUnit(), ""));
        jsonObject.put("meterReadingName", getMeterReadingEnum() == null ? "" : getMeterReadingEnum().getName());
        jsonObject.put("meterReading", getMeterReadingEnum() == null ? "" : getMeterReadingEnum().getCode());
        jsonObject.put("pointSystem", getPointSystem() == null ? "" : getPointSystem().getCode());
        jsonObject.put("pointSystemName", getPointSystem() == null ? "" : getPointSystem().getName());

        return jsonObject;
    }

    public JSONObject toJSONObjectSystem() {
        JSONObject jsonObject = super.toJSONObject();

        jsonObject.put("unit", CommonSugar.getTypedDefault(getUnit(), ""));
        jsonObject.put("meterReadingName", getPointSystem() == null ? "" : getPointSystem().getName());
        jsonObject.put("meterReading", getPointSystem() == null ? "" : getPointSystem().getCode());

        return jsonObject;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public MeterReadingEnum getMeterReadingEnum() {
        return meterReadingEnum;
    }

    public void setMeterReadingEnum(MeterReadingEnum meterReadingEnum) {
        this.meterReadingEnum = meterReadingEnum;
    }

    public PointSystem getPointSystem() {
        return pointSystem;
    }

    public void setPointSystem(PointSystem pointSystem) {
        this.pointSystem = pointSystem;
    }
}
